#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;
class Solution {
    public:
        int romanToInt(string s) {
        int ans = 0;
        map<string, int> myMap;
        myMap["M"] = 1000;
        myMap["CM"] = 900;
        myMap["D"] = 500;
        myMap["CD"] = 400;
        myMap["C"] = 100;
        myMap["XC"] = 90;
        myMap["L"] = 50;
        myMap["XL"] = 40;
        myMap["X"] = 10;
        myMap["IX"] = 9;
        myMap["V"] = 5;
        myMap["IV"] = 4;
        myMap["I"] = 1;
        for (int i = 0; i < s.size(); ){
            string str = s.substr(i, 2);
            if (myMap.count(str) != 0) {
                ans += myMap[str];
                i+=2;
            } else {
                string str1 = s.substr(i,1);
                ans += myMap[str1];
                i +=1;
            }
        }

        return ans;
     }
};


//test in online judge and all pass
int main(int argc, char **argv)
{
    int result;
    Solution mySolution;

    cout << "----------Test 1----------" << endl;
    result = mySolution.romanToInt("VIII");
    cout << result << endl;

    cout << "----------Test 2----------" << endl;
}
